Code error for date type attribute

Hello,

I have an object OBJ-1 in module A linked to  three objects(L-5, L-6, L-7) in Module B. My script just checks the earliest date value in the attribute "DXL_RequestedDate" of these linked objects(L-5,L-6,L-7) in module B and puts the value in DXL_EarliestDate attribute in OBJ-1 in module A.

But this script works perfectly if my target attribute is of type string, but if the type is changed to Date and i do a refresh DXL attributes, it gives Diagnostic log error. I need it to be of type date, for further codes.

I am attaching the script.

Please tell me what am i doing wrong/missing?

Thank you in advance!!

 

 

//  Generic DXL_Attribute Script to find out all the Earliest Requested Date for only_In_Link

LinkRef lref
ModName_ srcModRef
int srcAbsNumber
Module srcModule
Object srcObject

bool firstReqDateFound = false
Date earliesteReqDate = null
Date tmpReqDate = null
    
string objecInfo = null

for lref in obj<-"*" do
{
    srcAbsNumber = sourceAbsNo(lref)    
        srcModRef = source lref            

        srcModule = load(moduleVersion(srcModRef), false)
        srcObject = object(srcAbsNumber,srcModule)
        AttrDef ad = find(srcModule,"DXL_RequestedDate")
            if (!null ad)
        {
            // Logic to find out the Earliest Requested date\
        
            if (firstReqDateFound == false)
            {    
                if (srcObject."DXL_RequestedDate""" != "")
                {
                    earliesteReqDate = srcObject."DXL_RequestedDate"""
                    if (!null earliesteReqDate)
                    {
                        firstReqDateFound = true;
                    }
                }
            }
            else
            {    
                if (srcObject."DXL_RequestedDate""" != "")
                {
                    tmpReqDate = srcObject."DXL_RequestedDate"""
                    if(earliesteReqDate > tmpReqDate )
                    {
                        earliesteReqDate = tmpReqDate
                    }
                }
            }
        }
        else continue

}
if (!null earliesteReqDate)
{
    obj.attrDXLName = earliesteReqDate
}
else
{
obj.attrDXLName = ""
}

 


Gsquare - Mon Apr 09 02:01:06 EDT 2018

Re: Code error for date type attribute
davidcs - Mon Apr 09 12:11:24 EDT 2018

Do you know what line is causing the error?  Even with unhandled errors usually it will give you a line number.

Also, you should probably covert the date back to a  string before assigning it to the DXL attribute. 

string stringOf(Date d[, Locale l][, string s] )

 

Re: Code error for date type attribute
Gsquare - Tue Apr 10 00:15:20 EDT 2018

davidcs - Mon Apr 09 12:11:24 EDT 2018

Do you know what line is causing the error?  Even with unhandled errors usually it will give you a line number.

Also, you should probably covert the date back to a  string before assigning it to the DXL attribute. 

string stringOf(Date d[, Locale l][, string s] )

 

Hello davidics,

It gives a Diagnostic log Tool error, for a line 44.

But, my target and source attribute are both of type Date, then i think i do not need to convert it to string before assigning right?

Re: Code error for date type attribute
davidcs - Tue Apr 10 12:36:19 EDT 2018

No, you are correct i misread your post. I don't see anything wrong with line 44 or anything around it. May be one of those cases where you just start commenting out lines of code until you figure out which line is causing the exception.

Re: Code error for date type attribute
PekkaMakinen - Wed Apr 11 05:31:06 EDT 2018

Gsquare - Tue Apr 10 00:15:20 EDT 2018

Hello davidics,

It gives a Diagnostic log Tool error, for a line 44.

But, my target and source attribute are both of type Date, then i think i do not need to convert it to string before assigning right?

Could not test your code, but noticed that you are not checking the module or object being null before trying to use the values. So I would add this to your code:

 

        // Check for null modules
        if (null srcModule) continue        
        // Check for null objects
        if (null srcObject) continue

 

Re: Code error for date type attribute
Gsquare - Thu Apr 12 05:39:49 EDT 2018

PekkaMakinen - Wed Apr 11 05:31:06 EDT 2018

Could not test your code, but noticed that you are not checking the module or object being null before trying to use the values. So I would add this to your code:

 

        // Check for null modules
        if (null srcModule) continue        
        // Check for null objects
        if (null srcObject) continue

 

I just added this, but it still gives the same error.

Also logically, if this code works for String Type, it should also work for Date Type, so null module wont be the real issue.

Re: Code error for date type attribute
Mike.Scharnow - Thu Apr 12 07:06:49 EDT 2018

Gsquare - Thu Apr 12 05:39:49 EDT 2018

I just added this, but it still gives the same error.

Also logically, if this code works for String Type, it should also work for Date Type, so null module wont be the real issue.

1) I tried out parts of your code and could not find a problem, but what about your attribute "DXL_RequestedDate" ? From the attribute name, one might deduct that this is a DXL attribute Laughing

 

Could it be that the calculation of this attribute and the subsequent assignment of the result produces the error?

 

I'd suggest adding the lines

 tmpReqDate = srcObject."DXL_RequestedDate"""
 print "->" tmpReqDate "<-\n"
 print "->" earliesteReqDate "<-\n"
 if (earliesteReqDate > tmpReqDate)....

to see the problem.

 

2) Do you only get the diagnostic log error and nothing else, no DXL error?

 

3) I really do hope that the code you posted is NOT the DXL Code of DXL_RequestedDate, because in this code you ask for the current Value of DXL_RequestedDate. Requesting the current value of DXL_RequestedDate would again call the same DXL code -> this would mean an endless loop and it would explain the diagnostic log. see https://www.ibm.com/developerworks/community/forums/html/topic?id=8b4e0fca-ff37-4328-9b40-27277d036e26

Re: Code error for date type attribute
Gsquare - Fri Apr 13 04:46:33 EDT 2018

Mike.Scharnow - Thu Apr 12 07:06:49 EDT 2018

1) I tried out parts of your code and could not find a problem, but what about your attribute "DXL_RequestedDate" ? From the attribute name, one might deduct that this is a DXL attribute Laughing

 

Could it be that the calculation of this attribute and the subsequent assignment of the result produces the error?

 

I'd suggest adding the lines

 tmpReqDate = srcObject."DXL_RequestedDate"""
 print "->" tmpReqDate "<-\n"
 print "->" earliesteReqDate "<-\n"
 if (earliesteReqDate > tmpReqDate)....

to see the problem.

 

2) Do you only get the diagnostic log error and nothing else, no DXL error?

 

3) I really do hope that the code you posted is NOT the DXL Code of DXL_RequestedDate, because in this code you ask for the current Value of DXL_RequestedDate. Requesting the current value of DXL_RequestedDate would again call the same DXL code -> this would mean an endless loop and it would explain the diagnostic log. see https://www.ibm.com/developerworks/community/forums/html/topic?id=8b4e0fca-ff37-4328-9b40-27277d036e26

1) I tried out parts of your code and could not find a problem, but what about your attribute "DXL_RequestedDate" ? From the attribute name, one might deduct that this is a DXL attribute Laughing

Could it be that the calculation of this attribute and the subsequent assignment of the result produces the error?

 

Yes, it is a DXL Attribute

 

2)NO, Diagnostic Log error and also a DXL error at line 44 sometimes, sometimes different.

 

3)Yes, this is the exact code. I get it, so  you suggest to use a temp variable instead to store the srcObject."DXL_RequestedDate"??

Re: Code error for date type attribute
Mike.Scharnow - Fri Apr 13 06:34:14 EDT 2018

Gsquare - Fri Apr 13 04:46:33 EDT 2018

1) I tried out parts of your code and could not find a problem, but what about your attribute "DXL_RequestedDate" ? From the attribute name, one might deduct that this is a DXL attribute Laughing

Could it be that the calculation of this attribute and the subsequent assignment of the result produces the error?

 

Yes, it is a DXL Attribute

 

2)NO, Diagnostic Log error and also a DXL error at line 44 sometimes, sometimes different.

 

3)Yes, this is the exact code. I get it, so  you suggest to use a temp variable instead to store the srcObject."DXL_RequestedDate"??

I Re-read your initial need now -- the problem I described at 3) occurs when you try to access the value of "itself" (if you want to calculate a "next" value from the "current" value). In your scenario, you are in the DXL Attribute code Module A, Object 1  (A-1) and you try to get the value of B-5, not of A-1, so you don't have a problem of self-reference.

But you have to keep in mind that asking the value of B-5."DXL_RequestedDate" will in turn try to calculate its value from e.g. C-7, that means it has to open module C implicitely and if you are very unlucky, C-7 is linked to A-1 again. This whole mechanism of getting values from DXL Attributes to calculate other DXL attributes is very fragile. 

It would be better to either persist information in a non-calculated attribute or use a loop to gather all information directly. In your case, I think it's the easiest way if you use the code generated by the analysis wizard for recursive analyses and adopt it to your needs.

Re: Code error for date type attribute
Mike.Scharnow - Fri Apr 13 06:53:46 EDT 2018

Gsquare - Fri Apr 13 04:46:33 EDT 2018

1) I tried out parts of your code and could not find a problem, but what about your attribute "DXL_RequestedDate" ? From the attribute name, one might deduct that this is a DXL attribute Laughing

Could it be that the calculation of this attribute and the subsequent assignment of the result produces the error?

 

Yes, it is a DXL Attribute

 

2)NO, Diagnostic Log error and also a DXL error at line 44 sometimes, sometimes different.

 

3)Yes, this is the exact code. I get it, so  you suggest to use a temp variable instead to store the srcObject."DXL_RequestedDate"??

and something else: in your initial post you said that the problem occurs when you change the type of DXL_RequestedDate from string to Date. I hope that you did this type conversions for all modules at the same time, for A, B and C, before refreshing the DXL attributes? Otherwise this would also be a possible source of problems due to conversion issues

Re: Code error for date type attribute
Gsquare - Fri Apr 13 08:00:35 EDT 2018

Mike.Scharnow - Fri Apr 13 06:53:46 EDT 2018

and something else: in your initial post you said that the problem occurs when you change the type of DXL_RequestedDate from string to Date. I hope that you did this type conversions for all modules at the same time, for A, B and C, before refreshing the DXL attributes? Otherwise this would also be a possible source of problems due to conversion issues

Hello Mike,

 

Thank you for your detailed inputs.

But No, in Module B and C, the attributes are not DXL attributes, they are simple date type attributes with static values.

So what my code is doing exactly is:

Assuming ID OBJ-1 in ModA is linked to OBJ-5 in ModB and OBJ-7 in ModC.

It just goes to OBJ-5 in ModB first,takes the static value from date type attribute "RequestedDate" and stores in temp.(say 10th-mar-2019)

Then it goes to OBJ-7 in ModC ,takes the static value from date type attribute "RequestedDate"(say 12-Jun-2020) and then compares with the temp, which is the earlier date.

Then to the current DXL Attribute in Module A also of type Date, sets the comparison value(so value is 10-mar-2019). Here is where i get error, if this DXLAttribute is of type Date. If only i change this to type string and all other modules are kept as date still, it works fine.

Obviously then i add, obj.attrDXLName = stringOf(earliesteReqDate,"dd-mm-yy")

 

But, ideally i want it to be of type date.

 

Thank you!!

Re: Code error for date type attribute
Mike.Scharnow - Fri Apr 13 08:34:59 EDT 2018

Gsquare - Fri Apr 13 08:00:35 EDT 2018

Hello Mike,

 

Thank you for your detailed inputs.

But No, in Module B and C, the attributes are not DXL attributes, they are simple date type attributes with static values.

So what my code is doing exactly is:

Assuming ID OBJ-1 in ModA is linked to OBJ-5 in ModB and OBJ-7 in ModC.

It just goes to OBJ-5 in ModB first,takes the static value from date type attribute "RequestedDate" and stores in temp.(say 10th-mar-2019)

Then it goes to OBJ-7 in ModC ,takes the static value from date type attribute "RequestedDate"(say 12-Jun-2020) and then compares with the temp, which is the earlier date.

Then to the current DXL Attribute in Module A also of type Date, sets the comparison value(so value is 10-mar-2019). Here is where i get error, if this DXLAttribute is of type Date. If only i change this to type string and all other modules are kept as date still, it works fine.

Obviously then i add, obj.attrDXLName = stringOf(earliesteReqDate,"dd-mm-yy")

 

But, ideally i want it to be of type date.

 

Thank you!!

Well, seems I was confused as the attribute you are reading from srcObject (ModB-5, ModC-7) is called "DXL_RequestedDate", so I guessed that it is a DXL attribute and I guessed that your target attribute in the target module (ModA-1) is also called "DXL_RequestedDate".

 

line 44 in the code that you posted is the line  >> { <<

in 

                    tmpReqDate = srcObject."DXL_RequestedDate"""
                    if(earliesteReqDate > tmpReqDate )
                    {

, right?

 

This indicates that eithere there is a problem when reading srcObject."DXL_RequestedDate" or that one of the two variables get assigned to some invalid content.

I cannot see how the type of the target attribute (ModA-"DXL_RequestedDate") is of importance, when you assign the value of ModB-5."DXL_RequestedDate" to a variable of type Date. 

 

But if I understood you correctly, you say that if the attribute in all three modules, A, B and C is of type string, everything works, and if it is of type Date in all three modules you get the diagnostic log, right?

 

Which output did you get when you added the "print" lines I suggested? Do earliestReqDate and tmpReqDate have valid content? If so, can you somehow see why a comparison of these dates should produce a diagnostic log?

Re: Code error for date type attribute
Gsquare - Thu Apr 26 04:37:13 EDT 2018

Mike.Scharnow - Fri Apr 13 08:34:59 EDT 2018

Well, seems I was confused as the attribute you are reading from srcObject (ModB-5, ModC-7) is called "DXL_RequestedDate", so I guessed that it is a DXL attribute and I guessed that your target attribute in the target module (ModA-1) is also called "DXL_RequestedDate".

 

line 44 in the code that you posted is the line  >> { <<

in 

                    tmpReqDate = srcObject."DXL_RequestedDate"""
                    if(earliesteReqDate > tmpReqDate )
                    {

, right?

 

This indicates that eithere there is a problem when reading srcObject."DXL_RequestedDate" or that one of the two variables get assigned to some invalid content.

I cannot see how the type of the target attribute (ModA-"DXL_RequestedDate") is of importance, when you assign the value of ModB-5."DXL_RequestedDate" to a variable of type Date. 

 

But if I understood you correctly, you say that if the attribute in all three modules, A, B and C is of type string, everything works, and if it is of type Date in all three modules you get the diagnostic log, right?

 

Which output did you get when you added the "print" lines I suggested? Do earliestReqDate and tmpReqDate have valid content? If so, can you somehow see why a comparison of these dates should produce a diagnostic log?

Hello,

 

Thank you for the inputs. i have figured out the problem.

The line 44 error was in the DXL->Refrersh DXL AttributesScript in doors v9.3

This script in turn calls a script "wipeattr" in which the line 44 sets the value to null at first,before evaluating anything. Since, date type is being set to null, it was giving DXL Diagnostic log error.

But, luckily this bug was solved in version 9.6 and above. So now, even if my final target attribute is of type Date and also all the source attributes are of type Date, it does not throw an error.

But i would have to still look at the "Analysis Wizard" suggestion you gave to make the script faster.

 

thanks a lot to all for this